Andrewlytics attempts to project the preseason strength of each team by calculating a score between 0-1 based on each team's roster. This score is an average of a roster's individual players' scores, which are also on a scale 0-1. The bottom 4 individual player scores on each roster are dropped before computing the overall roster score. Each individual score is based on propritary Andrewlytics metrics broken down as follows:
Teams featuring players who were injured for significant portions of the season, as well as rookies, may be projected lower than others. Lack of data from previous years makes them difficult to project.
# Import proprietary Andrewlytics Data
master_metrics = pd.read_excel("/Users/andrewlee/Repositories/FantasyFootball/JupyterNotebooks/InputData/2020_DRAFT_SHEET.xlsx", sheet_name="DRAFT_BOARD")
teams = pd.read_excel("/Users/andrewlee/Repositories/FantasyFootball/JupyterNotebooks/InputData/teams2021.xlsx", sheet_name="teams")
# Picks by position
picks_by_position = get_picks_by_position(teams, master_metrics)
# Generate individual player Scores
teams["RelativePositionStrength"] = teams.apply(lambda row: get_relative_position_strength(row.Player, master_metrics, picks_by_position), axis=1)
teams["Consistency"] = teams.apply(lambda row: get_consistency(row.Player, master_metrics), axis=1)
teams["Explosiveness"] = teams.apply(lambda row: get_explosiveness(row.Player, master_metrics), axis=1)
# Average scores for each team (drop bottom 4)
scores = calculate_team_scores(teams)
# Grouped bar chart of each team's overall score, positional strength, consistency, and explosiveness
plot_summary(scores)
# Plot Positional Strength
fig = px.bar(scores.sort_values(by=["PositionalStrength"], ascending=False), x='Team', y='PositionalStrength', title="Relative Positional Strength by Team")
fig.update_traces(marker_color='blue')
fig.show(renderer="notebook")
# Plot Consistency
fig = px.bar(scores.sort_values(by=["Consistency"], ascending=False), x='Team', y='Consistency', title="Consistency by Team")
fig.update_traces(marker_color='green')
fig.show(renderer="notebook")
# Plot Explosiveness
fig = px.bar(scores.sort_values(by=["Explosiveness"], ascending=False), x='Team', y='Explosiveness', title="Explosiveness by Team")
fig.update_traces(marker_color='red')
fig.show(renderer="notebook")
import pandas as pd
from pandas import DataFrame
import plotly.express as px
import plotly.graph_objects as go
def get_picks_by_position(teams, master_metrics):
picks_by_position = {"QB":0, "RB":0, "WR":0, "TE":0, "K":0, "DST":0}
for index, row in teams.iterrows():
if row.Player not in master_metrics["PLAYER"].to_list():
continue
current_position = master_metrics.loc[master_metrics["PLAYER"]==row.Player, "POSITION"].item()
picks_by_position[f"{current_position}"] += 1
return picks_by_position
def get_consistency(player:str, master_data:DataFrame):
if player not in master_data["PLAYER"].to_list():
return 0
consistency = master_data.loc[master_data["PLAYER"]==player, "Consistency"].item()
return consistency
def get_explosiveness(player:str, master_data:DataFrame):
if player not in master_data["PLAYER"].to_list():
return 0
explosiveness = master_data.loc[master_data["PLAYER"]==player, "Explosiveness"].item()
return explosiveness
def get_relative_position_strength(player:str, master_data:DataFrame, picks_by_position:dict):
if player not in master_data["PLAYER"].to_list():
return 0
rank = master_data.loc[master_data["PLAYER"]==player, "POSITION_RANK"].item()
position = master_data.loc[master_data["PLAYER"]==player, "POSITION"].item()
if rank > picks_by_position[f"{position}"]:
return 0
else:
return 1 - (rank / picks_by_position[f"{position}"])
def calculate_team_scores(teams:DataFrame):
team_names = list(set(teams["Team"].to_list()))
scores_df = pd.DataFrame()
for team in team_names:
consistencies = teams.loc[teams["Team"] == team, "Consistency"].sort_values(ascending=False)
consistency = consistencies[0:12].mean()
explosivenesses = teams.loc[teams["Team"] == team, "Explosiveness"].sort_values(ascending=False)
explosiveness = explosivenesses[0:12].mean()
positional_strengths = teams.loc[teams["Team"] == team, "RelativePositionStrength"].sort_values(ascending=False)
positional_strength = positional_strengths[0:12].mean()
overall_score = 0.5*positional_strength + 0.25*consistency + 0.25*explosiveness
data = {"Team" : team, "PositionalStrength" : positional_strength, "Consistency": consistency, "Explosiveness":explosiveness, "Overall Score": overall_score}
scores_df = scores_df.append(data, ignore_index=True)
return scores_df.sort_values(by=["Overall Score"], ascending=False, ignore_index=True)
def plot_summary(scores:DataFrame):
team_names = scores["Team"].to_list()
fig = go.Figure(data=[
go.Bar(name='Overall Score', x=team_names, y=scores["Overall Score"], marker_color='black'),
go.Bar(name='Relative Positional Strength', x=team_names, y=scores["PositionalStrength"], marker_color='blue'),
go.Bar(name='Consistency', x=team_names, y=scores["Consistency"], marker_color='green'),
go.Bar(name='Explosiveness', x=team_names, y=scores["Explosiveness"], marker_color='red')
])
fig.update_layout(barmode='group',title_text='Summary of Scores by Team')
fig.update_xaxes(title_text='Team')
fig.update_yaxes(title_text='Score (0-1)')
fig.show(renderer="notebook")